package com.xyy.ebattery.tcp.start.runner;

import com.xyy.ebike.account.common.constant.AccountRedisKey;
import com.xyy.redis.RedisMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

/**
 * @Description TODO
 * @Author JIA BOYAN
 * Date 2025/6/16 12:58
 */
@Slf4j
@Component
public class RedisRunner implements CommandLineRunner {

    @Autowired
    private RedisMapper redisMapper;

    @Override
    public void run(String... args) throws Exception {
        int retry = 3;
        int times = 0;
        String key = AccountRedisKey.NAME.format("xyy");
        while (times<retry) {
            try {
                times++;
                String name = redisMapper.get(key);
                log.info("test redis command. key={} value={}", key,name);
                return;
            } catch (Exception e) {
                log.warn("test redis command fail. times={}",times);
            }
        }
        if(times>retry){
            throw new RuntimeException("test redis command fail");
        }
    }


}
